<%-- 
    Document   : validate
    Created on : Mar 17, 2015, 9:52:07 PM
    Author     : user
--%>

<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="com.uniq.db.ConnectionFactory"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
  <%
String userName=request.getParameter("userName");
String password=request.getParameter("password");
String role=request.getParameter("role");      
Connection con=ConnectionFactory.getConnection();
Statement s=con.createStatement();
ResultSet rs=s.executeQuery("select * from login");
boolean flag=false;

while(rs.next())
{
if((rs.getString("userName").equals(userName))&&(rs.getString("password").equals(password))&&(rs.getString("role").equalsIgnoreCase(role)))
{
    session.setAttribute("userName",userName);
    session.setAttribute("password",password);
    session.setAttribute("role",role);
    
    flag=true;
}
       
}

if(flag==true)
{
response.sendRedirect("products.jsp");    
}
else if(userName.equals("admin")&&password.equals("admin")&&role.equals("admin"))
 {
    response.sendRedirect("AdminHeader.jsp");
}
else
{
response.sendRedirect("login.html");    
}

%>
    </body>
</html>
